const DataExchange = require("../../Controls/DataExchange")
import Dialog from '../../miniprogram_npm/vant-weapp/dialog/dialog.js'
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    product_info: {},
    address:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var selectedAddressID = DataExchange.get_selectedAddress();
    if (selectedAddressID) {
      for (var i = 0; i < app.globalData.address.length; i++) {
        if (app.globalData.address[i].id == selectedAddressID) {
          this.setData({ address: app.globalData.address[i] });
          return;
        }
      }
    }

    var data = DataExchange.get_productData();

    var address = null;
    if (app.globalData.address == 0) {
      address = { name: "添加收获地址", phonenum: "", city: "", detail: "" };
    }
    else {
      for (var i = 0; i < app.globalData.address.length; i++) {
        if (app.globalData.address[i].checked) {
          address = app.globalData.address[i];
          break;
        }
      }

      if (address == null) {
        address = app.globalData.address[0];
      }
    }


    this.setData({ product_info: data, address: address });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  btnAddressIvk: function()
  {
    wx.navigateTo({
      url: '../addressmgr/addressmgr?isSelect=true',
    })
  },

  btnCommitIvk:function()
  {
    //Dialog.alert({ message: "充值审核中，暂不开放下单！", zIndex:9999});
  }
})